<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Provinces
 *
 * @author 耿鸿飞 <15911185633>
 */
class Sys_Provinces extends Model
{
    protected $table_province = "sys_provinces";
    protected $table_city = 'sys_city';

    /**
     * 获取全部的城市列表
     */
    public function getProvince(){
        $rs = array();
        $sql = sprintf("SELECT * FROM %s WHERE Fstatus='Yes' ORDER BY Fpid ASC",$this->table_province);
        $list = $this->getResults($sql);
        if($list){
            foreach($list AS $val){
                $rs[$val['Fpid']] = $val;
            }
        }
        return $rs;
    }
    /**
     * 获取全部的城市列表
     * @param type $pid
     */
    public function getCitys($pid = 0){
        $rs = array();
        $sql = sprintf("SELECT * FROM %s WHERE Fstatus='Yes'",$this->table_city);
        if($pid > 0){
            $sql = sprintf("SELECT * FROM %s WHERE Fstatus='Yes' AND Fpid=%d",$this->table_city,$pid);
        }
        $list = $this->getResults($sql);
        if($list){
            foreach($list AS $val){
                $rs[$val["Fcid"]] = $val;
            }
        }
        return $rs;
    }
    /**
     * 获取城市的全部信息
     */
    public function getAll(){
        $rs = array();
        $rs = $this->getProvince();
        $citys = $this->getCitys();
        foreach($citys AS $val ){
            if(!isset($rs[$val['Fpid']]['list'])){
                $rs[$val['Fpid']]['list'] = array();
            }
            $rs[$val['Fpid']]['list'] = $val;
        }
        return $rs;
    }
}

?>
